package com.hhd.flow.engine.cmd.impl;

import com.hhd.flow.engine.utils.CommonUtils;
import com.hhd.flow.engine.vo.FlowModel;
import com.hhd.flow.engine.vo.UserTask;
import com.hhd.flow.entity.FlowComment;
import com.hhd.flow.entity.FlowProcessInstance;
import com.hhd.flow.entity.FlowUserTask;
import com.hhd.flow.exception.FlowException;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.util.List;

@Setter
@Getter
@SuperBuilder(toBuilder = true)
public class QuerySubtractAbleUserSignCommand extends BaseCommand<List<UserTask>> {
    String flowUserTaskId;

    //下面是运行时的参数
    private FlowUserTask flowUserTask;
    private FlowModel flowModel;
    private UserTask currentUserTaskNode;

    @Override
    public List<UserTask> execute() {
        prepare();
        return flowModel.getNextCountUserSignsById(currentUserTaskNode);
    }

    private void prepare() {
        flowUserTask = getEngine().getFlowUserTaskService().getById(flowUserTaskId);
        CommonUtils.isEmptyThrow(flowUserTask, new FlowException("没有找到用户任务：" + flowUserTaskId));
        if (flowUserTask.getNotify()) {
            throw new FlowException("知会任务不支持加签的操作");
        }

        flowModel = loadFlowModelByProcessInstanceId(flowUserTask.getProcessInstanceId());
        currentUserTaskNode = flowModel.getUserTaskById(flowUserTask.getTaskDefinitionId());
    }
}
